package com.my.mq.ms;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

public class MessageReceive {

	@Autowired
	 private JmsTemplate jmsTemplate;
     
	    /**
	     * 接收到的消息
	     */
	    public TextMessage receive(Destination destination) {
	        TextMessage tm = (TextMessage) jmsTemplate.receive(destination);
	        try {
	            System.out.println("指定队列" + destination.toString() + "接收到的消息是："
	                    + tm.getText());
	        } catch (JMSException e) {
	            e.printStackTrace();
	        }
	        
	        return tm;
	        
	    }
}
